#include "ContextTreeNode.h"


ContextTreeNode::ContextTreeNode(ContextTreeNode *prnt)
	: parent(prnt), onesCount(0), zerosCount(0), probability(0.0f),
	  leftChild(0l), rightChild(0l)
{
}

ContextTreeNode::~ContextTreeNode(void)
{
}

void ContextTreeNode::setLeftChild(ContextTreeNode *lChild)
{	
	if(leftChild)
		throw ChildOverwriting::ChildOverwriting();

	leftChild=lChild;
}
void ContextTreeNode::setRightChild(ContextTreeNode *rChild)
{
	if(rightChild)
		throw ChildOverwriting::ChildOverwriting();

	rightChild=rChild;
}

void ContextTreeNode::clearNode()
{
	probability=0.0f;
	onesCount=0;
	zerosCount=0;
}




void ContextTreeNode::countAndSetProbability(double lutValue)
{
	if(leftChild && rightChild)
		probability = (lutValue + leftChild->getProbability()*rightChild->getProbability())*0.5;
	else
		probability = lutValue;
}